package com.eiisan.user.service.impl;

import com.eiisan.base.enums.UserStatusEnum;
import com.eiisan.core.util.api.Result;
import com.eiisan.user.mapper.UserMapper;
import com.eiisan.user.model.domain.User;
import com.eiisan.user.model.dto.UserInfoDto;
import com.eiisan.user.service.AuthorityService;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: AuthorityServiceImpl
 * @Author: gragonfly
 * @Date: 2019/6/28
 */
@Service
public class AuthorityServiceImpl implements AuthorityService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Result<UserInfoDto> getUserInfoByMobile(String mobile) {
        Preconditions.checkArgument(StringUtils.isNotEmpty(mobile));
        User user = userMapper.getUserByMobile(mobile);
        if (user == null) {
            return Result.fail("未查询到用户信息!");
        }
        if (user.getUserStatus().equals(UserStatusEnum.FORBIDDEN.getVal())) {
            return Result.fail("用户已禁用!");
        }
        UserInfoDto userInfoDto = new UserInfoDto();
        BeanUtils.copyProperties(user, userInfoDto);
        return Result.success(userInfoDto);
    }
}
